import requests
import json_test

def send_http_request(method, url, headers=None, data=None, params=None):
    """
    发送HTTP请求的通用方法

    :param method: 请求方法 (GET, POST, PUT, DELETE等)
    :param url: 请求的URL
    :param headers: 请求头 (可选)
    :param data: 请求体数据 (可选)
    :param params: 查询参数 (可选)
    :return: 响应对象
    """
    try:
        response = requests.request(method=method, url=url, headers=headers, json=data, params=params)
        response.raise_for_status()  # 如果响应状态码不是200，抛出异常
        return response
    except requests.exceptions.RequestException as e:
        print(f"HTTP request failed: {e}")
        return None


# 示例用法
if __name__ == "__main__":
    url = "http://127.0.0.1:8001/query_stats/get-report"
    headers = {
        "Content-Type": "application/json",
    }

    data = {
        "tenant_id": 1008,
        "user_id": 1008,
        "metrics": [],
        "profile_ids": [
            "4285263511617980"
        ],
        "start_date": "20250401",
        "end_date": "20250414",
        "time_period": "weekly",
        "topic": "campaign_inter_day",
        "prev_type": [
            1
        ],
        "asin_search": {
            "searchType": "asin",
            "asins": [
                {
                    "asin": "B01NBCZKCZ",
                    "profileId": "4285263511617980"
                },
                {
                    "asin": "B091KN2724",
                    "profileId": "4285263511617980"
                },
                {
                    "asin": "B07GTFBD1Y",
                    "profileId": "4285263511617980"
                }
            ]
        },
        "group": ""
    }
    # strs = json.dumps(data)
    # print(strs)
    response = send_http_request("POST", url, headers=headers, data=data)
    if response:
        print(response.text)

